<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
		<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
    href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>

		
		<script>

			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [
                                {
                                    id : listDisplayEId + '_btn_save',
                                    text : 'Excel报表导出',
                                    iconCls : 'icon-print',
                                    handler : function() {
                                        excel();
                                    }
                                }           
							],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						});
			};
			$(document).ready(function() {
				initCustId();
				initList('listDisplay');
			});
			
			//导出报表
			function excel(){
                $('#searchForm').form('submit',
                        {
                            url:'<c:url value='/check/exportCheckExcel.do'/>', //查询提交路径
                            onSubmit:function()//提交按钮相应函数
                            {
                                return $('#searchForm').form('validate');
                            },
                            success:function(data){
                                data = eval( "("+data+")" );
                                if(data.success){
                                    $.messager.alert("提示", "导出成功！",'info', function(){
                                        window.close();
                                    });
                                }else{
                                    $.messager.alert("提示", data.msg, 'warning');
                                }
                            },
                            error:function(){
                                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                return;
                            }
                        }
                );
            }
			$(function() {  
				$('#orderBy').combobox({   
                    data:[{"orderBy":"0","orderByName":"订单排序"},{"orderBy":"1","orderByName":"默认价格比排序"}],   
                    editable:false, //不可编辑状态  
                    cache: false,  
                    valueField:'orderBy',     
                    textField:'orderByName',  
                });    
				$('#supId').combobox({   
		            url:"<c:url value='/store/pulldownSupId.do?space=2'/>",   
		            editable:false, //不可编辑状态  
		            cache: false,  
		            valueField:'supId',     
		            textField:'supName',  
		            value:0
		        });
                $('#materType').combobox({   
                    url:"<c:url value='/mater/pulldownMaterType.do?space=1'/>",   
                    editable:true, //不可编辑状态  
                    cache: false,  
                    panelHeight: '150',  
                    valueField:'materType',     
                    textField:'materTypename',
                    value:0
                    }); 
                $('#materType1').combobox({   
                    url:"<c:url value='/mater/pulldownMaterType.do?space=1'/>",   
                    editable:true, //不可编辑状态  
                    cache: false,  
                    panelHeight: '150',  
                    valueField:'materType',     
                    textField:'materTypename',
                    width : 'auto'
                    }); 
                
            });
			function initCustId(){
				$.ajax({
			        async : false,
			        url : "<c:url value='/shop/getShopIdByUserId.do'/>",
			        type : "post",
			        success : function(data) {
			        	if(typeof(data)=='string'){
			        		data =JSON.parse(data);
			            }
			            if(data.success){
			            	document.getElementById('custIdAll').value = data.shopId;
			            }
			        }
			    });
			}
			function searchInfo(){
				if($('#ordDateStart').combobox('getValue') ==''){
					alert("起始日不能为空");
				}else if($('#ordDateEnd').datebox('getValue') ==''){
					alert("截止日不能为空");
				}else{
				        $('#listDisplay').datagrid('load', {
				        	initFlag : 1,
				        	ordDateEnd : $('#ordDateEnd').datebox('getValue'),
				        	ordDateStart : $('#ordDateStart').datebox('getValue'),
				        	materType : $('#materType').combobox('getValue'),
				        	custIdAll : $('#custIdAll').val(),
				        	materName : $('#materName').val(),
				        	supId : $('#supId').combobox('getValue'),
				        	orderBy :  $('#orderBy').combobox('getValue')
						});  
				}
			}
        //查看详细内容
        function  goDetailedContent(val,rowData,rowIndex){
            return '<a href="#" onclick="constructionManager(\'' + rowData.materId+ '\',\'' + rowData.ordDateStart+ '\',\''+rowData.ordDateEnd+'\',\''+rowData.custIdAll+'\',\''+rowData.supId +'\')">'+val+'</a>  '
        }
        function constructionManager(materId,ordDateStart,ordDateEnd,custIdAll,supId) {
            var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/check/goCheckDetailedForAdmin.do'/>"+"?materId="+materId+"&ordDateStart="+ordDateStart+"&ordDateEnd="+ordDateEnd+"&custIdAll="+custIdAll+"&supId="+supId,"sun","width=1200px,height=600px,status=no,scrollbars=yes");
            new_win.focus();
        }
    </script>
			</head>
			<body>
			<table width="98%">
			<tr><td>
			<div style="height: auto; width:100%;background: #fafafa; padding: 5px;" class="easyui-panel" title="检索条件" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
					<form id="searchForm" name="searchForm" method="post">
						<div>
		            	<table cellpadding="5">
								<tr>
									<td>起始日期</td>
									<td><input class="easyui-datebox" editable="false" id="ordDateStart" name="ordDateStart" required="true"></input></td>
									<td>截止日期</td>
                                    <td><input class="easyui-datebox" editable="false" id="ordDateEnd" name="ordDateEnd" required="true"></input></td>
									<td>材料类别：</td>
                                    <td><input class="easyui-combobox" id="materType" editable="false" name="materType"></input></td>
                                    <td>材料名：</td>
                                    <td><input class="easyui-validatebox" id="materName" editable="false" name="materName"></input></td>
                                </tr>
                                <tr>
                                    <td>供货商</td>
                                    <td><input class="easyui-combobox" name="supId" id="supId" editable="false"  /></td>
		                    	</tr>
		                    	<tr>
		                    	    <td>排序方式：</td>
                                    <td><input class="easyui-combobox" id="orderBy" editable="false" name="orderBy" value='0'></input></td>
                                    <td><input type="button" onclick="searchInfo()" value="查询"></td>
                                </tr>
		                    	<td><input class="easyui-validatebox" editable="false" id="custIdAll" name="custIdAll" hidden = 'true' ></input></td>
		                    	
		                </table>
						</div>
					</form>
				</div>
			</td></tr>
            </table>
			<table width="98%">
		      <tr>
		      <td>
			     <table id="listDisplay" title="货物批量列表" 
				    iconCls="icon-list" singleSelect="false" idField="id"
				    url="<c:url value="/check/findCheck.do"/>" loadMsg="请稍候......"
				    pagination="true" pageSize="10"
				    pageList="[10,20,30,40,50,100]" sortName="storeInId"
				    rownumbers="true" sortOrder="asc" showFooter="true">
			     <thead>
				    <tr>
					   <th field="id" width="80"  sortable="true" editor="text" hidden = "true">ID
					   </th>
					   <th field="materId" width="80"  sortable="true" >材料Id
					   </th>
					   <th field="materTypeString" width="80"  sortable="true" >种类
                       </th>
					   <th field="materName" width="180"  sortable="true" >材料名
					   </th>
					   <th field="specifications" width="80"  sortable="true" >规格
					   </th>
					   <th field="brands" width="80"  sortable="true" >品牌
                       </th>
                       <th field="materWeightAll" width="80"  sortable="true" >数量总计
                       </th>
                       <th field="unit" width="80" sortable="true" >单位
                       </th>
                       <th field="materValueAllEvey" width="80" sortable="true" >平均价钱
                       </th>
                       <th field="materValueAll" width="80" sortable="true" >已结款总价钱
                       </th>
                       <th field="percent" width="80" sortable="true" >价格百分比
                       </th>
                       <th field="ordDateStart" width="80" sortable="true" hidden="true">检索开始时间
                       </th>
                       <th field="ordDateEnd" width="80" sortable="true" hidden="true">检索结束时间
                       </th>
                       <th field="custIdAll" width="80" sortable="true" hidden="true">检索客户id
                       </th>
                       <th field="supId" width="80" sortable="true" hidden="true">检索供货商id
                       </th>
                       <th field="content" width="120" sortable="true" formatter="goDetailedContent">根据检索条件
                       </th>
 				    </tr>
			     </thead>
			     </table>
			</td>
			</tr>
		</table>
	</body>
</html>